<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jedlo extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('jedlo_model');
		$this->load->model('dieta_model');
	}
	
	
	function pridaj()
	{
		$this->load->library('form_validation');
		$this->form_validation->set_rules('name', 'Názov jedla', 'trim|required');
		$this->form_validation->set_rules('weight', 'Hmotnosť', 'trim|required');
		$this->form_validation->set_rules('value', 'Výživová hodnota', 'trim|required');
		$this->form_validation->set_rules('items', 'Ingrediencie', 'trim|required');
		
		if ($this->form_validation->run())
		{
			$this->dieta_model->pridanie_ingrediencii($_POST['items']);		
			$this->jedlo_model->pridaj();
			redirect('admin');
		}
		else
		{
			// chyba
		}	
		$data['title'] = 'NIS - Pridanie jedla';
		$this->load->view('templates/header', $data);
		$this->load->view('project/jedlo_view');
		$this->load->view('templates/footer');
	}	  	
}